﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Decoration.Comm
{
    /// <summary>
    /// 读取配置文件
    /// "RedisConfig": {
    ///是否打开缓存1是0否
    ///"IsOpenCache": "0",
    /// "ReadWriteHosts": "127.0.0.1:6379,password=123456",
    /// "ReadOnlyHosts": "127.0.0.1:6379,password=123456"
    ///}
    ///ConfigurationHelper.GetConfiguration().GetSection("RedisConfig:ReadWriteHosts").Value;
    ///ConfigurationHelper.GetConfiguration()["RedisConfig:ReadWriteHosts"]
    /// </summary>
    public class ConfigurationHelper
    {
        private static IConfiguration configuration = null;
        //静态方法
        public static IConfiguration GetConfiguration()
        {
            if (configuration == null)
            {
                configuration = new
                         ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                        .Add(new JsonConfigurationSource
                        {
                            Path = "appsettings.json",
                            ReloadOnChange = true
                        })
                        .Build();
            }
            return configuration;
        }
    }
}
